<%@page contentType="text/plain" pageEncoding="UTF-8" import="com.mop.dinnerbook.dao.*,java.util.*,com.mop.dinnerbook.bean.*"%>
<% 
        Boolean locked = (Boolean)application.getAttribute("lock");
        System.out.println("--------------------"+locked+"-----------------------");
        Date now = Calendar.getInstance().getTime();
        Calendar cald = Calendar.getInstance();
        //订餐时间期限
        cald.set(Calendar.HOUR_OF_DAY, 22);
        cald.set(Calendar.MINUTE, 0);
        cald.set(Calendar.SECOND, 0);
        Date timeLimit = cald.getTime();
        if(now.compareTo(timeLimit)>0) locked = true;
        if(locked == null || locked.booleanValue() == false){
            String action = request.getParameter("action");
            int mid = Integer.parseInt(request.getParameter("mid"));
            RecordDAO dao = new RecordDAO();
            ActionDAO adao = new ActionDAO();
            String result = "";
            if(action != null  && mid > 0){
                    String actionIp = request.getRemoteHost();
                    Action act = new Action();
                    act.setActionIp(actionIp);
                    act.setAname(action);
                    act.getMember().setMid(mid);
                    adao.saveAction(act);
                    if(action.equals("book")){
                            if(dao.bookDinner(mid,actionIp))result = "订购成功";
                            else result = "订购失败";	
                    }else{
                            if(dao.cancelDinner(mid,actionIp))result = "取消成功";
                            else result = "取消失败";	
                    }
                    out.write(result);
            }
	}else{
            out.write("订餐时间已过");
        }
%>
